﻿@{
    ViewData["Title"] = "Home Page";
    Layout = "_Layout";
    var goods = Model;
}
<fieldset class="layui-elem-field" style="margin: 20px">
    <legend>物资申请提交表</legend>
    <div class="layui-field-box">
        <form class="layui-form layui-form-pane" action="" lay-filter="example">

            <div class="layui-row">
                <div class="layui-col-xs6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">申请部门</label>
                        <div class="layui-input-block">
                            <input type="text" name="username" lay-verify="title" autocomplete="off" placeholder="@goods.Departmentid" class="layui-input layui-disabled" id="departmentid">
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">申请教师ID</label>
                        <div class="layui-input-block">
                            <input type="text" name="username" lay-verify="title" autocomplete="off" placeholder="@goods.Teacherid" class="layui-input layui-disabled" id="teacherid">
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-row layui-col-space5">
                <div class="layui-col-md4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">申请物资</label>
                        <div class="layui-input-block">
                            <input type="text" name="username" lay-verify="title" autocomplete="off" placeholder="请输入申请的物资名称" class="layui-input" id="goodsid">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">申请数量</label>
                        <div class="layui-input-block">
                            <input type="text" name="username" lay-verify="title" autocomplete="off" placeholder="请输入申请的物资数量" class="layui-input" id="numid">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">申请单价</label>
                        <div class="layui-input-block">
                            <input type="text" name="username" lay-verify="title" autocomplete="off" placeholder="请输入申请的物资单价" class="layui-input" id="priceid">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入大致内容" class="layui-textarea" name="desc" id="remarkid"></textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="submit" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="demo1" id="addgoods" value="音速提交" /> @*这是个提交按钮*@
                </div>
            </div>
        </form>
    </div>
</fieldset>
@section Scripts{
    <script src="~/js/jquery.js"></script>
    <script src="~/layui-v2.5.5/layui/layui.all.js" charset="utf-8"></script>
    <script>
        $("#addgoods").on("click", function () {//这个位置没必要拿值，监听提交事件！
            //event.preventDefault();//阻止页面自动刷新
            var departmentidd ='@goods.Departmentid';//获取部门ID
            var teacheridd ='@goods.Teacherid';
            var goodsidd = $("#goodsid").val();
            var numidd = $("#numid").val();
            var priceidd = $("#priceid").val();
            var remarkidd = $("#remarkid").val();

            $.ajax({
                url: '/Api/AddMaterialapply2',
                type: "post",
                DataType: "json",
                data: {
                    'Departmentid': departmentidd,
                    'Tid': teacheridd,
                    'Goodsname': goodsidd,
                    'Goodsnum': numidd,
                    'Goodsprice': priceidd,
                    'Remarks': remarkidd    //把上面新建的局部变量的值以data发送到后端，对应每个类的各项数据
                },
                success: function (data) {//如果成功就返回一个success msg
                    alert(data.msg);
                },
                error: function (error) {//失败就返回一个error msg
                    alert(error.msg);
                }
            })
            return false;
        });//提交物资申请表
    </script>
}